define([ "Zepto", "underscore", "Backbone", "Handlebars",
         "views/corsolaurea/courseitemview"
         ], function($, _, Backbone, Handlebars, CourseItemView, template) {

	var CoursesView = Backbone.View.extend({

		template : Handlebars.compile(template),

		initialize : function() {
			this.model.bind("reset", this.render, this);
		},

		render : function(eventName) {
			 
			$(this.el).empty();
		
			_.each(this.model.models,
				function(course) {
					//alert('course: ' + course.get('corso').nome); not docente
					﻿$(this.el).append(new CourseItemView({
						tagName : 'a', //Crea un nuovo tag <a> invece di usarne uno già presente nel DOM
						attributes : {
							'href' : '#courses/'+course.get('objectId')
						},
						﻿model : course
					}).render().el);
				 },
				 this);
		}

	});
	

	return CoursesView;
});
